package com.jt.resource.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * 定义资源服务器的配置
 * @EnableGlobalMethodSecurity
 * 思考访问资源是否通过方法，当不允许对这个方法进行访问，就意味不允许访问资源
 *  *  prepostEnabled 表示在执行资源方法之前
 * */
/**/
@EnableResourceServer   //启动资源服务配置
@EnableGlobalMethodSecurity(prePostEnabled = true)  //表示启动方法层面的权限控制
@Configuration
public class ResourceConfig extends ResourceServerConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception {
//        super.configure(http);
        //1.禁用跨域访问（假如不禁用，我们使用postman类似的工具发请求时）
        http.csrf().disable();
        //2.配置资源访问规则
        http.authorizeRequests()
                .antMatchers("/resource/**")
                .authenticated()//认证
                .anyRequest().permitAll();

    }
}
